// pages/me/me.js
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: false,
    avatarUrl: wx.getStorageSync('avatarUrl'),
    serverUrl: app.globalData.serverUrl,
    height: app.globalData.height,
    width: app.globalData.width,
    barHeight: app.globalData.barHeight,
    myOrderActive1: false,
    myOrderActive2: false,
    myOrderActive3: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    wx.getSetting({
      success(res) {
        that.setData({
          userInfo: res.authSetting['scope.userInfo'],
        })
      }
    })
    wx.request({
      url: app.globalData.serverUrl + '/admin/me/countlist',
      method: 'POST',
      data: {
        token: wx.getStorageSync('token'),
      },
      success(res) {
        that.setData({
          done: res.data.listCount.done,
          not: res.data.listCount.not
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  login: function (res) {
    this.setData({
      userInfo: true,
      avatarUrl: res.detail.userInfo.avatarUrl,
      myOrderActive: 0,
    })
    wx.setStorageSync('nickName', res.detail.userInfo.nickName)
    wx.setStorageSync('avatarUrl', res.detail.userInfo.avatarUrl)
  },

  orderClick(event) {
    var that = this;
    var menu = event.currentTarget.dataset.replyType
    if (that.data.userInfo == true) {
      if (menu == 0) {
        this.setData({
          myOrderActive1: !that.data.myOrderActive1
          // myOrderActive: (!that.data.myOrderActive)
        })
      }
      if (menu == 1) {
        this.setData({
          myOrderActive2: !that.data.myOrderActive2
        })
      }
      if (menu == 2) {
        this.setData({
          myOrderActive3: !that.data.myOrderActive3
        })
      }
    }
  },

  tolist(e) {
    wx.switchTab({
      url: '/pages/list/list',
    })
  }
})